home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / grafica / amhelios / ct_delta.cpp < prev    next >
C/C++ Source or Header  |  1999-01-01  |  3KB  |  104 lines

  1. ////////////////////////////////////////////////////////////
  2. //
  3. //  CT_DELTA.CPP- Cubic Tetrahedron Delta Form Factor Class
  4. //
  5. //  Version:    1.03A
  6. //
  7. //  History:    94/08/23 - Version 1.00A release.
  8. //              94/12/16 - Version 1.01A release.
  9. //              95/02/05 - Version 1.02A release.
  10. //              95/07/21 - Version 1.02B release.
  11. //              96/02/14 - Version 1.02C release.
  12. //              96/04/01 - Version 1.03A release.
  13. //
  14. //  Compilers:  Microsoft Visual C/C++ Professional V1.5
  15. //              Borland C++ Version 4.5
  16. //
  17. //  Author:     Ian Ashdown, P.Eng.
  18. //              byHeart Software Limited
  19. //              620 Ballantree Road
  20. //              West Vancouver, B.C.
  21. //              Canada V7S 1W3
  22. //              Tel. (604) 922-6148
  23. //              Fax. (604) 987-7621
  24. //
  25. //  Copyright 1994-1996 byHeart Software Limited
  26. //
  27. //  The following source code has been derived from:
  28. //
  29. //    Ashdown, I. 1994. Radiosity: A Programmer's
  30. //    Perspective. New York, NY: John Wiley & Sons.
  31. //
  32. //  It may be freely copied, redistributed, and/or modified
  33. //  for personal use ONLY, as long as the copyright notice
  34. //  is included with all source code files.
  35. //
  36. ////////////////////////////////////////////////////////////
  37.  
  38. #include "ct_delta.h"
  39.  
  40. // Static delta form factor row pointer array
  41. float *CubicDelta::delta_array[CT_DeltaDim];
  42.  
  43. // Static delta form factor array
  44. float CubicDelta::ff_array[CT_FormDim];
  45.  
  46. CubicDelta::CubicDelta()        // Class constructor
  47. {
  48.   int i = 0;                    // Form factor array index
  49.   int left, right, top, bottom; // Index boundaries
  50.   int row, col;                 // Current indices
  51.   double delta;                 // Cell width
  52.   double diag_delta;            // Diagonal cell width
  53.   double area;                  // Cell area
  54.   double diag_area;             // Diagonal cell area
  55.   double y, z;                  // Cell center
  56.   double diag_y, diag_z;        // Diagonal cell center
  57.   double r2;                    // Cell distance squared
  58.  
  59.   // Initialize index boundaries
  60.   left = top = 0;
  61.   right = FF_ArrayRes - 1;
  62.   bottom = FF_ArrayRes / 2;
  63.  
  64.   // Initialize cell values
  65.   delta = (CT_MaxCoord - CT_MinCoord) / FF_ArrayRes;
  66.   diag_delta = delta / 2.0;
  67.   area  = delta * delta;
  68.   diag_area  = area / 2.0;
  69.   y = z = CT_MaxCoord - diag_delta;
  70.  
  71.   // Calculate delta form factors
  72.   for (row = top; row < bottom; row++)
  73.   {
  74.     // Save delta form factor array row pointer
  75.     delta_array[row] = &(ff_array[i]);
  76.  
  77.     for (col = left; col < right; col++)
  78.     {
  79.       // Calculate square of cell distance
  80.       r2 = y * y + z * z + 1;
  81.  
  82.       // Calculate cell delta form factor
  83.       ff_array[i++] = (float) (area * (y + z + 1) / (PI * r2
  84.           * r2 * sqrt(3.0)));
  85.  
  86.       y -= delta;
  87.     }
  88.  
  89.     // Calculate square of diagonal cell distance
  90.     diag_y = y + diag_delta;
  91.     diag_z = z + diag_delta;
  92.     r2 = diag_y * diag_y + diag_z * diag_z + 1;
  93.  
  94.     // Calculate diagonal cell delta form factor
  95.     ff_array[i++] = (float) (diag_area * (diag_y + diag_z +
  96.         1) / (PI * r2 * r2 * sqrt(3.0)));
  97.  
  98.     left++;
  99.     right--;
  100.     y = z -= delta;
  101.   }
  102. }
  103.  
  104.